Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add meta code verify #311

Merged
merged 37 commits into from
Apr 25, 2023
Merged

Conversation

spiritbroski
Copy link
Contributor

@spiritbroski spiritbroski commented Mar 9, 2023

closes #277

Video Demo

https://www.youtube.com/watch?v=BZfnLPGep-4

Description

This is a modified version of https://github.com/facebookincubator/meta-code-verify by facebook, to describe what it does in simple terms,it is basically a web extension for checking if the js doesnt get tampered by creating a merkle tree both in a client and in a server you can read this https://wiki.mozilla.org/Security/Binary_Transparency, if you see in the code that i push you can see that i create a scripts https://github.com/spiritbroski/human-protocol/blob/24b39697a51096c9f982b00b44a469b0c11470de/packages/apps/escrow-dashboard/scripts/generateMerkleTree.ts to generate merkle tree in vite then push the root of the merkle tree to ipfs, i design it to look like the whatsapp binary transparency manifest:

image

this is what it look like in our apps:

image

the difference is i remove hash_function , and for the whatsapp they push their merkle root into cloudflare like this https://staging-api.privacy-auditability.cloudflare.com/v1/hash/whatsapp.com/2.2313.8 and this is ours https://bafkreicgn4acvov2oilxnbeootwvxdnakn4a6lcf3sgs2ubi5u76wcdrny.ipfs.nftstorage.link/ its the same and we are much more resilient coz its decentralized in ipfs however cloudflare is centralized server, so this is a brief description of what i've been working on

How to use

As this is a web extension first you need to have either chrome based browser or firefox, in this demo i use brave browser, first navigate to packages/apps/meta-code-verify and run this script:

$ yarn
$ yarn build-local-dev

Then go to your browser and open this url brave://extensions/ turn on developer mode if you haven't:

image

Then click load unpacked:

image

Then navigate to the dist/chrome folder of meta-code-verify then click select folder

image

If successful it will show something like this:

image

Now go to packages/apps/escrow-dashboard and run this command:

$ yarn
$ yarn build --mode development 

Wait until it finish building then run

$ yarn start-prod

Go to your browser and navigate to http://localhost:3000, if you click on the web extension earlier you can see the green checkmark which mean our code is not tampered

image

So how to check if our code is getting tampered first we need to stop the yarn start-prod command if youre on linux its simply CTRL+C then now go to index.html in escrow-dashboard packages and add this <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>:

image

and run yarn build --mode development again and followed by yarn start-prod and when you go to http://localhost:3000 again you will see red exclamation mark:

image

It means that one or more script is not in the merkle tree and if you download it you will get list of all js files and its source code in gzip files so you can check it yourself, ok thats it waiting for your review

@CLAassistant
Copy link

CLAassistant commented Mar 9, 2023

CLA assistant check
All committers have signed the CLA.

@vercel
Copy link

vercel bot commented Mar 9, 2023

@spiritupbro is attempting to deploy a commit to the HUMAN Protocol Team on Vercel.

A member of the Team first needs to authorize it.

@spiritbroski spiritbroski marked this pull request as ready for review March 28, 2023 10:45
Copy link
Collaborator

@leric7 leric7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target branch should be develop

packages/apps/meta-code-verify/yarn.lock Outdated Show resolved Hide resolved
@spiritbroski spiritbroski changed the base branch from main to develop April 4, 2023 13:19
@spiritbroski spiritbroski requested a review from leric7 April 4, 2023 13:35
packages/apps/meta-code-verify/CODE_OF_CONDUCT.md Outdated Show resolved Hide resolved
packages/apps/meta-code-verify/CONTRIBUTING.md Outdated Show resolved Hide resolved
packages/apps/meta-code-verify/LICENSE.md Outdated Show resolved Hide resolved
packages/apps/meta-code-verify/README.md Outdated Show resolved Hide resolved
packages/apps/meta-code-verify/yarn.lock Outdated Show resolved Hide resolved
Copy link
Collaborator

@portuu3 portuu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this error when I run yarn build-local-dev
image

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 6, 2023 via email

@spiritbroski
Copy link
Contributor Author

@portuu3 please pull again and try again it turns out 'build' not getting pushed it basically a script for rollup, it works now

@portuu3
Copy link
Collaborator

portuu3 commented Apr 11, 2023

@portuu3 please pull again and try again it turns out 'build' not getting pushed it basically a script for rollup, it works now

I am getting this now when I run yarn build --mode development:
image

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 11, 2023 via email

@portuu3
Copy link
Collaborator

portuu3 commented Apr 13, 2023

Now if builds ok for both code verify and dashboard, but I get this without modifying index.html
image

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 13, 2023 via email

@spiritbroski
Copy link
Contributor Author

Oh wait @portuu3 could you please try using incognito? Because in the original meta-code-verify by facebook there are a list of whitelist extension if there are a blacklisted extension it will trigger validation warning coz sometimes browser extension also inject a script see this one facebookincubator/meta-code-verify#139 i think i need to fix the docs again

@mrhouzlane
Copy link
Contributor

https://github.com/spiritbroski/human-protocol/blob/meta-code-verify/packages/apps/escrow-dashboard/README.md#yarn-run-build

For me extension is not showing up for http://localhost:3000/, but showing for https://web.whatsapp.com/.
I have added incognito mode and load unpacked. Have tried the extension both on Brave and Chrome. Same result.

Localhost
Screenshot 2023-04-22 at 11 08 42 AM

Whatsapp
Screenshot 2023-04-22 at 11 05 40 AM

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 22, 2023

@mrhouzlane can you tell me how you run this? Are you using this readme https://github.com/spiritbroski/human-protocol/blob/meta-code-verify/packages/apps/meta-code-verify/README.md to run? i fresh clone the repo and it work for me this is my reproduction step:

  1. clone meta code verify branch
  2. go to packages/apps/escrow-dashboard adding necessary .env run yarn then yarn start-prod
  3. go to packages/apps/meta-code-verify run yarn then yarn build-local-dev
  4. Load unpacked packages/apps/meta-code-verify/dist/chrome in brave browser
  5. go to localhost:3000 and then i got validated screen i dont have any other extension installed for this reproduction step

image

are you also run it just like me? and are you adding something in index.html? have you tried refreshing it, is it the same? could you please disable any other extension other than meta code verify first then try reload again?

@mrhouzlane
Copy link
Contributor

@mrhouzlane can you tell me how you run this? Are you using this readme https://github.com/spiritbroski/human-protocol/blob/meta-code-verify/packages/apps/meta-code-verify/README.md to run? i fresh clone the repo and it work for me this is my reproduction step:

  1. clone meta code verify branch
  2. go to packages/apps/escrow-dashboard adding necessary .env run yarn then yarn start-prod
  3. go to packages/apps/meta-code-verify run yarn then yarn build-local-dev
  4. Load unpacked packages/apps/meta-code-verify/dist/chrome in brave browser
  5. go to localhost:3000 and then i got validated screen i dont have any other extension installed for this reproduction step

image

are you also run it just like me? and are you adding something in index.html? have you tried refreshing it, is it the same? could you please disable any other extension other than meta code verify first then try reload again?

Working now.
If you can those steps in readme would be good.

Modify the 2.
2. go to packages/apps/escrow-dashboard adding necessary .env run yarn build --mode development then then yarn start-prod

Screenshot 2023-04-22 at 7 30 09 PM

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 22, 2023

@mrhouzlane can you tell me how you run this? Are you using this readme https://github.com/spiritbroski/human-protocol/blob/meta-code-verify/packages/apps/meta-code-verify/README.md to run? i fresh clone the repo and it work for me this is my reproduction step:

  1. clone meta code verify branch
  2. go to packages/apps/escrow-dashboard adding necessary .env run yarn then yarn start-prod
  3. go to packages/apps/meta-code-verify run yarn then yarn build-local-dev
  4. Load unpacked packages/apps/meta-code-verify/dist/chrome in brave browser
  5. go to localhost:3000 and then i got validated screen i dont have any other extension installed for this reproduction step

image
are you also run it just like me? and are you adding something in index.html? have you tried refreshing it, is it the same? could you please disable any other extension other than meta code verify first then try reload again?

Working now. If you can those steps in readme would be good.

Modify the 2. 2. go to packages/apps/escrow-dashboard adding necessary .env run yarn build --mode development then then yarn start-prod

Screenshot 2023-04-22 at 7 30 09 PM

@mrhouzlane which readme? escrow-dashboard or meta-code-verify? also could you please try using metamask on? is it throwing error? if it is then my app is correct, also use https://github.com/spiritbroski/human-protocol/tree/meta-code-verify/packages/apps/meta-code-verify#allowlist to allow to use metamask without disabling it first

@mrhouzlane
Copy link
Contributor

@mrhouzlane can you tell me how you run this? Are you using this readme https://github.com/spiritbroski/human-protocol/blob/meta-code-verify/packages/apps/meta-code-verify/README.md to run? i fresh clone the repo and it work for me this is my reproduction step:

  1. clone meta code verify branch
  2. go to packages/apps/escrow-dashboard adding necessary .env run yarn then yarn start-prod
  3. go to packages/apps/meta-code-verify run yarn then yarn build-local-dev
  4. Load unpacked packages/apps/meta-code-verify/dist/chrome in brave browser
  5. go to localhost:3000 and then i got validated screen i dont have any other extension installed for this reproduction step

image
are you also run it just like me? and are you adding something in index.html? have you tried refreshing it, is it the same? could you please disable any other extension other than meta code verify first then try reload again?

Working now. If you can those steps in readme would be good.
Modify the 2. 2. go to packages/apps/escrow-dashboard adding necessary .env run yarn build --mode development then then yarn start-prod
Screenshot 2023-04-22 at 7 30 09 PM

@mrhouzlane which readme? escrow-dashboard or meta-code-verify?

Here : https://github.com/spiritbroski/human-protocol/tree/meta-code-verify/packages/apps/meta-code-verify

Steps are already detailed, all good.
Removing other extensions I think made it work.

Do you have any tests for generateMerkleTree function ?

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 22, 2023

Removing other extensions I think made it work.

uhm, no basically the correct flow if there is any other extension it will throw an error or a risk message so thats why i ask you that, and thats why i create allowlist so you can allow some of the extension that you deemed safe to use, you can try it like this install metamask and go to localhost:3000 it will throw validation error

Do you have any tests for generateMerkleTree function ?

nope, i will add that i guess

@spiritbroski
Copy link
Contributor Author

@mrhouzlane adding the generateMerkleTree test check again

@posix4e posix4e self-requested a review April 22, 2023 14:17
@posix4e posix4e removed their request for review April 22, 2023 14:17
@vercel vercel bot temporarily deployed to Preview – fortune-exchange-oracle-server April 22, 2023 14:18 Inactive
Copy link
Contributor

@posix4e posix4e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good on first view but i'll leave it to others to approve

@mrhouzlane
Copy link
Contributor

@mrhouzlane adding the generateMerkleTree test check again

Test working, good for me.

@posix4e
Copy link
Contributor

posix4e commented Apr 23, 2023

Let's fix the lint and tests

@spiritbroski
Copy link
Contributor Author

@posix4e ok

@vercel vercel bot temporarily deployed to Preview – fortune-exchange-oracle-server April 23, 2023 20:32 Inactive
@spiritbroski
Copy link
Contributor Author

@posix4e i think most of the check failing is not coming from the package that i work with

@portuu3
Copy link
Collaborator

portuu3 commented Apr 24, 2023

@posix4e i think most of the check failing is not coming from the package that i work with

Merge develop branch and check if it gets fixed

@spiritbroski
Copy link
Contributor Author

spiritbroski commented Apr 24, 2023 via email

@spiritbroski
Copy link
Contributor Author

@portuu3 it said already up to date

image

@vercel vercel bot temporarily deployed to Preview – fortune-exchange-oracle-server April 25, 2023 01:54 Inactive
@portuu3 portuu3 dismissed posix4e’s stale review April 25, 2023 08:01

Changes required made

@portuu3 portuu3 merged commit 12c9e7c into humanprotocol:develop Apr 25, 2023
m00n620 pushed a commit that referenced this pull request May 4, 2023
Add meta code verify to check integrity of dashboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement "meta-code-verify" in "eth-kv-store"
7 participants